<template>
	<view class="bg-white p-20">
		<view class="h5 font-weight-bold title">
			用户登录
		</view>
		<view>
			<uv-form labelPosition="left" :model="form" :rules="rules" ref="form">
				<uv-form-item prop="userInfo.name" borderBottom>
					<uv-input type="number" placeholder='请输入手机号' v-model="form.name" border="none">
					</uv-input>
				</uv-form-item>
				<uv-form-item prop="userInfo.name" borderBottom>
					<uv-input type="number" placeholder='请输验证码' v-model="form.name" border="none">
						<template v-slot:suffix>
							<uv-code ref="uCode" @change="codeChange" seconds="20" changeText="X秒重新获取"></uv-code>
							<uv-text @click="getCode" :text="tips" color="#e87a47" size="mini"></uv-text>
						</template>
					</uv-input>
				</uv-form-item>
				<uv-button class="mt-50" shape="circle" color="#e87a47" text="登录" customStyle="margin-top: 10px"
					@click="submit"></uv-button>
			</uv-form>
		</view>
		<view style="height: 500px; background-color: #fff;">

		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				tips: '',
				form: {
					name: ''
				},
				rules: {}
			}
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						// toast('验证码已发送');
						uni.showToast({
							title: '验证码已发送',
							icon: 'none'
						});
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.showToast({
						title: '倒计时结束后再发送',
						icon: 'none'
					});
					// toast('倒计时结束后再发送');
				}
			},
			submit() {

			}
		}
	}
</script>

<style scoped>
	.title {
		text-align: center
	}
</style>